/**
 * @param {string} url
 * @returns {Object}
 */
export function param2Obj (url) {
  const search = url.split('?')[1]
  if (!search) {
    return {}
  }
  return JSON.parse(
    '{"' +
      decodeURIComponent(search)
        .replace(/"/g, '\\"')
        .replace(/&/g, '","')
        .replace(/=/g, '":"')
        .replace(/\+/g, ' ') +
      '"}'
  )
}

export function deepClone (source) {
  if (!source && typeof source !== 'object') {
    throw new Error('error arguments', 'deepClone')
  }
  const targetObj = source.constructor === Array ? [] : {}
  Object.keys(source).forEach(keys => {
    if (source[keys] && typeof source[keys] === 'object') {
      targetObj[keys] = deepClone(source[keys])
    } else {
      targetObj[keys] = source[keys]
    }
  })
  return targetObj
}
export function formatCatalogTreeDis(tree){
  tree.forEach(data => {
    if(!Array.isArray(data.children)){
      let newarr = []
      data.children={
        ... data.children,
        text:'',
      }
      newarr.push(data.children)
      data.children = newarr
    }
     if(!data.children[0].children){
       data.children[0].children = [{text:''}]
     }
    if(!Array.isArray(data.children[0].children)){
      let newarr = []
      newarr.push(data.children[0].children)
      data.children[0].children = newarr
    }

    if(data.children[0].children[0].text!=''){
       formatCatalogTreeDis(data.children)
     }
  })
}
